<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/layouts/taglib.jsp"%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<title>自定义字段列表</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 内容管理 <span class="c-gray en">&gt;</span> 自定义字段管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<div class="cl pd-5 bg-1 bk-gray mt-20"> 
		<span class="l">
			<a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> 
			<a href="javascript:;" onclick="field_open('添加字段','${ctx}/fieldCategory/add?categoryId=${categoryId }','','510')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加自定义字段</a>
		</span> 
		<span class="r">共有数据：<strong id="totalCount">88</strong> 条</span> 
	</div>
	<div class="mt-20">
	<table class="table table-border table-bordered table-striped"  id="example">
		<thead>
			<tr class="text-c">
				<th width="25"><input type="checkbox" name="" value=""></th>
				<th width="40">英文名称</th>
				<th width="100">中文名称</th>
				<th width="90">字段名称</th>
				<th width="150">默认值</th>
				<th width="100">操作</th>
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>
	</div>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="${ctxLib }/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="${ctxLib }/layer/2.4/layer.js"></script>
<script type="text/javascript" src="${ctxStatic }/h-ui/js/H-ui.min.js"></script> 
<script type="text/javascript" src="${ctxStatic }/h-ui.admin/js/H-ui.admin.js"></script>
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="${ctxLib }/datatables/1.10.0/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="${ctxLib }/laypage/1.2/laypage.js"></script>
<script type="text/javascript">
	$(function(){
		query();
	});
	
	function query(){
		var url = "${ctx }/fieldCategory/list";
		$("#example").dataTable({
			"searching" : false,
			"bPaginate" : false,		//开启分页
			"bAutoWidth": true, 		//是否自适应宽度
			"bProcessing":true,		//是否显示“正在处理”这个提示信息
			"bSort":false,				//是否让各列具有按列排序功能
			"bStateSave":true,			//是否打开客户端状态记录功能
			"bDestroy":true,			//dataTable绑定时，将之前的那个数据对象清除掉，换以新的对象设置
			"serverSide":true,			//开启服务器处理模式
			"sAjaxSource":url,			//请求资源路径
			/*
			 使用ajax，在服务端处理数据
			 sSource:即是"sAjaxSource"
			 aoData:要传递到服务端的参数
			 fnCallback:处理返回数据的回调函数
			 */
			 "fnServerData": function(sSource, aoData, fnCallback){
				 var data = {"aodata" : JSON.stringify(aoData),"categoryId":"${categoryId}"};
				  $.ajax( { 
					  'type' : 'POST', 
					  "url": sSource, 
					  "dataType": "json", 
					  "data": data,
					  "success": function(resp) { 
						  	$("#totalCount").text(resp.iTotalRecords);
					   		fnCallback(resp);
					   } 
				  }); 
			 }, 
			 "columns": [
					        { "data": "id" },
					        { "data": "enName" },
					        { "data": "showName" },
					        { "data": "fieldName" },
					        { "data": "defaultValue" },
					        { "data": "id"}
					    ],
					    "columnDefs": [{
					        targets: 0,
					        render: function(data, type, row, meta) {
					            return '<input type="checkbox" name="checkitem"  id="check'+data+'" value="'+data+'"/>';
					        }
					    },{
					    	targets: 5,
					        render: function(data, type, row, meta) {
					            return '<a title="编辑" href="javascript:;" onclick="pre_edit(\'字段编辑\',\'${ctx}/fieldCategory/edit\',\''+data+'\');" class="ml-5" style="text-decoration:none">'+
					            '<i class="Hui-iconfont center-font">&#xe6df;</i></a> <a title="删除" href="javascript:;" onclick="datadel(\''+data+'\')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont center-font">&#xe6e2;</i></a>';
					        }
					    }],
					    "rowCallback": function (row, data, displayIndex) {//行定义
				     		 $(row).attr("class", "text-c");
						}
		});
	}
	
	/*打开新窗口*/
	function field_open(title,url){
		var index = layer.open({
			type: 2,
			title: title,
			content: url
		});
		layer.full(index);
	}
	
	/*字段-编辑*/
	function pre_edit(title,url,id){
		if(id != null && id != 0){
			var index = layer.open({
				type: 2,
				title: title,
				content: url+"?id="+id
			});
			layer.full(index);
		}
	}
	
	function datadel(id){
		var ids=new Array();
		if(id != null){
			ids.push(id);
		}else{
			$('input[name="checkitem"]:checked').each(function(){ 
				ids.push($(this).val());
			});
		}
		if(ids.length == 0){
			layer.alert("您还未选择任何字段");
			return;
		}
		layer.confirm('确认要删除这些字段么?',function(index){
			$.ajax({
				type: 'POST',
				url: '${ctx}/fieldCategory/delete',
				data:{ids:ids},
				dataType: 'json',
				success: function(data){
					if(data.success){
						layer.msg('已删除!',{icon:1,time:1000},function(){
							query();
						});
					}else{
						layer.msg(data.message,{icon:2,time:1000});
					}
				},
				error:function(data) {
					console.log(data.msg);
				},
			});
		});
	}
	</script> 
</body>
</html>